<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>emit传事件</title>
</head>

<body>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <div id="Application">
        <child @on-change="emitFn"></child>
    </div>
    <script>
        const App = Vue.createApp({
            setup() {
                const emitFn = v => {
                    console.log(v)
                    //接收传递的值并打印
                }

                return {
                    emitFn
                }
            },
        });

        //子组件
        const childBlock = {
            setup(props, ctx) {
                const clickBtn = () => {
                    ctx.emit("on-change", "我在子组件里，需要传递出去")
                    //自定义触发事件，传出值
                }
                return {
                    clickBtn
                }

            },

            template: ' <button type="button" @click="clickBtn">hi~</button>'
        }
        App.component("child", childBlock);

        //挂载
        App.mount("#Application");
    </script>
</body>

</html>